﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace zjbks
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void login_Click(object sender, EventArgs e)
        {
            Model.UserInfoEntity userInfo = new Model.UserInfoEntity();
            Test test = new Test();
            userInfo.ID = name.Text.Trim();
            userInfo.Pwd = pwd.Text.Trim();
            HttpCookie cookie =new HttpCookie("type");
            
            BLL.BUserInfo bUser = new BLL.BUserInfo();
            Model.UserInfoEntity userInfo1 = new Model.UserInfoEntity();
            userInfo1 = bUser.GetUserInfo(userInfo.ID);
            Response.Cookies.Add(cookie);
            if (userInfo1 == null)
            { //失败
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('没有此用户！');</script>");
                return;
            }
            if (userInfo1.Type=="考生"&&!test.idnumber(userInfo.ID))
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('身份证号有误！');</script>");
                return;
            }
            cookie.Value = userInfo1.Type;
            if (userInfo.Pwd == userInfo1.Pwd)
            {
                if(userInfo1.Type == "考生")
                {
                    Session["id"] = name.Text.Trim();
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='jiazai.aspx';</script>");
                }
                //登陆成功
                if (userInfo1.Type == "生源地学校")
                {
                    Session["id"] = name.Text.Trim();
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='ShenHeXinXi.aspx';</script>");
                }
                if (userInfo1.Type == "考试院" )
                {
                    Session["id"] = name.Text.Trim();
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='KaoShiYuanIndex.aspx';</script>");
                }
                if (userInfo1.Type == "管理员" )
                {
                    Session["id"] = name.Text.Trim();
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='AdminAdd.aspx';</script>");
                }
            }
            else
            {
                //失败
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('用户名或密码错误！');</script>");
            }
        }
        protected void regedit_Click(object sender, EventArgs e)
        {
            Model.UserInfoEntity userInfo = new Model.UserInfoEntity();
            userInfo.ID = zname.Text.Trim();
            BLL.BUserInfo bUser = new BLL.BUserInfo();
            Model.UserInfoEntity user = new Model.UserInfoEntity();
            user = bUser.GetUserInfo(userInfo.ID);

            userInfo.Pwd = zpwd.Text.Trim();
                        
            if (user == null)
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('用户名错误或没有此用户！');</script>");
            }
            else
            {
                if(user.Pwd==userInfo.Pwd)
                {
                    userInfo.Pwd = zpwd1.Text;
                    userInfo.Type = user.Type;
                    if (bUser.ModUserInfo(userInfo) > 0)
                    {
                        //成功
                        ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改成功！');</script>");
                    }
                    else
                    {
                        //失败
                        ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改失败！');</script>");
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('原密码错误！');</script>");
                }

            }
            

        }
    }

}